package ae.pcfc.etks.online.itworx.ehs.web.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import ae.pcfc.etks.online.itworx.ehs.web.constants.GlobalConstants;

public class ServiceValidator {

	public static boolean validateMobile(String mobileNumber) {
		if (mobileNumber == null || mobileNumber.trim().equals("")) {
			return false;
		}
		Pattern mobileFormatPattern = Pattern
				.compile(GlobalConstants.MOBILE_REGEXP);
		Matcher mobileFormatMatcher = mobileFormatPattern.matcher(mobileNumber);
		return mobileFormatMatcher.matches();
	}

	public static boolean validateEmail(String email) {
		if (email == null || email.equals("")) {
			return false;
		}
		Pattern pat = Pattern.compile(GlobalConstants.MAIL_REGEXP);
		Matcher matcher = pat.matcher(email.toString());
		if (matcher.matches()) {
			return true;
		}

		return false;
	}

	public static String getDDMMYYYFromDate(Date date) {
		try {
			SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
			String formattedDate = df.format(date);
			return formattedDate;
		} catch (Exception e) {
			return "";
		}

	}

	public static boolean validateBBC(String bcc) {
		if (bcc == null || bcc.equals("")) {
			return false;
		}
		return validateLength(bcc, GlobalConstants.BCC_LENGTH);
	}
	
	public static boolean validateRequestedBy(String requestedBy) {
		if (requestedBy == null || requestedBy.equals("")) {
			return false;
		}
		return validateLength(requestedBy, GlobalConstants.REQUESTEDBY_LENGTH);
	}
	
	public static boolean validateContactPersonName(String name) {
		if (name == null || name.equals("")) {
			return false;
		}
		return validateLength(name, GlobalConstants.CONTACT_PERSON_NAME_LENGTH);
	}
	
	public static boolean validateDocumentTypeTitle(String title) {
		if (title == null || title.equals("")) {
			return false;
		}
		return validateLength(title, GlobalConstants.DOCUMENT_TYPE_TITLE_LENGTH);
	}

	public static boolean validateString(String s) {
		if (s == null || s.equals("")) {
			return false;
		}
		return true;
	}

	private static boolean validateLength(String s, int length) {
		if (s.length() <= length) {
			return true;
		}
		return false;
	}

	public static void main(String[] args) {
		System.out.println(ServiceValidator
				.validateEmail("semsembug@hotmail.com"));
	}

}
